package com.obligatorio.domain.convertidores;

import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.obligatorio.domain.Pais;
import com.obligatorio.domain.Sector;
import com.obligatorio.domain.Usuario;
import com.obligatorio.ejb.ManejadorSector;

public class SectorConverter implements Converter {
	private static final Logger log = Logger.getLogger(SectorConverter.class
			.getName());

	@EJB
	private ManejadorSector mSector2;

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		log.info("getAsObject()");
		try {

			HttpSession session = (HttpSession) FacesContext
					.getCurrentInstance().getExternalContext()
					.getSession(false);
			Usuario tmpUsr = (Usuario) session.getAttribute("user");
			Sector objSector = new Sector(arg2);
			tmpUsr.setSector(objSector);

			session.setAttribute("user", tmpUsr);

			// Sector tmpSector = mSector2.ObtenerUnSector(arg2);
			// log.info(tmpSector.toString());
			// return tmpSector;
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
		}

		return null;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		// TODO Auto-generated method stub
		return null;
	}

}
